<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib  uri="/struts-tags" prefix="s"%>
<style type="text/css">
body {
	font: 12px/16px Arial, Helvetica, sans-serif;
}

#fileQueue {
	width: 400px;
	height: 300px;
	overflow: auto;
	border: 1px solid #E5E5E5;
	margin-bottom: 10px;
}
</style>
<script type="text/javascript">
$(document).ready(function() {  
    $("#fileInput").uploadify({
    'uploader'       : 'dwz/uploadify/scripts/uploadify.swf',  
    'script'         : 'projectmanagement/fileUpdate!fileUpdate.action',
    'scriptData'	 : {'auxiliaryId':$('#auxiliaryId').val(),'uuid': $('#uuid').val(),'moduleName':$('#moduleName').val(),'count': $('#count').val(),'typeid':$('#typeid').val(),'typename':$('#typename').val()},
    'folder' 		 : '/uploads',
    'method'         : 'post',
    'cancelImg'      : 'dwz/uploadify/cancel.png',
 	'fileDataName'   : 'fileInput',  
 	'queueID'        : 'fileQueue', //和存放队列的DIV的id一致 
    'auto'           : false,  //是否自动上传
    'multi'          : true,  //是否多文件上传
    'sizeLimit'      : 4294967296,  //限制大4G
    'simUploadLimit' : 5,  //限制上传个数
    'buttonText'     : 'Browse Files',  //不支持中文
    'displayData'    : 'percentage',  //有speed和percentage两种，一个显示速度，一个显示完成百分比 
    'fileDesc'       : '支持格式:xls/docx/xlsx/jpg/doc/csv/rar/zip/png/jpeg', //如果配置了以下的'fileExt'属性，那么这个属性是必须的 
    'fileExt'        : '*.doc;*.docx;*.xlsx;*.xls;*.csv;*.bmp;*.jpg;*.png;*.zip;*.rar;*.jpeg',//允许的格式
		'onSelectOnce' : function(event,data){
			$("#count").attr("value",data.fileCount);
		},
	    //上传失败
	    onError: function(event, queueID, fileObj,errorObj){ 
            alert("文件:" + fileObj.name + "上传失败"); 
        }, 
        //取消上传
        onCancel: function(event, queueID, fileObj){ 
            alert("取消了" + fileObj.name); 
        },
        onComplete: function(event,queueId,fileObj,response,data){
        	var arr = new Array();
        	arr = response.split(",");
        	if(arr.length > 1){
	        	var unm = fRandomBy(1,10000);
	        	var str = "\<a href='javascript:void(0);' onClick='return del(&#39;"+arr[0]+"&#39;,&#39;"+arr[1]+"&#39;,&#39;"+unm+"&#39;);'  title='确定要删除吗?'\>\<img src='dwz\/uploadify\/cancel.png' border='0'\>\<\/a\>";
	        	$("#result").html($("#result").html()+"&nbsp;&nbsp;"+"\<span id='"+unm+"'\>"+"\<a href='"+arr[2]+"' title='文件另存为'\>\<font color='blue'\>"+arr[0]+"\<\/font\>\<\/a\>"+str+"<br \/>\<\/span\>");
        	}
        },
      	//上传成功
        'onAllComplete' : function(event,data) {
			alert("共成功上传"+data.filesUploaded +"个文件");
			$.pdialog.closeCurrent();
		}
    });  
}); 
function dump_obj(myObject) {
	  var s = "";
	  for (var property in myObject) {
	   s = s + "\n "+property +": " + myObject[property] ;
	  }
	  alert(s);
	}
function fRandomBy(under, over){ 
	switch(arguments.length){ 
	case 1: return parseInt(Math.random()*under+1); 
	case 2: return parseInt(Math.random()*(over-under+1) + under); 
	default: return 0; 
	} 
}

//赋值typeid
function typeName(){
	var typeid = $("#c_T_Sys_FileType_filetypeId").val();
	var typename = $("#c_T_Sys_FileType_filetypeId").find("option:selected").text();
	$("#typeid").attr("value",typeid);
	$("#typename").attr("value",typename);
}
</script> 
	<div class="pageContent">
		<div class="pageFormContent" layoutH="57">
			<dl>
				<dt>附件类型：</dt>
				<dd>
					<s:select label="" headerKey="c_T_Sys_FileType.filetypeId" headerValue="--请选择--"
						list="list_C_T_Sys_FileType" listValue="fileTypeName" listKey="filetypeId"
						name="c_T_Sys_FileType.filetypeId" cssStyle="height:22px;width:250px;" onChange="typeName();"/>
				</dd>
			</dl>
			<dl>
				<dt>选择附件</dt>
				<dd>
				<!-- 获取文件名称 -->
				<input type="hidden" name="fileName" id="fileName"/>
				<!-- 获取typename -->
				<input type="hidden" name="typename" id="typename"/>
				<!-- 获取TYPEid -->
				<input type="hidden" name="typeid" id="typeid"/>
				<!-- 附件个数 -->
				<input type="hidden" name="count" id="count"/>
				<!-- 项目ID -->
				<input type="hidden" name="c_T_Sys_File.auxiliaryId" id="auxiliaryId" value="${auxiliaryId}"/>
				<input type="hidden" name="c_T_Sys_File.uuid" id="uuid" value="${projectUuid}"/>
				<!-- 模块名称-->
				<input type="hidden" name="c_T_Sys_File.moduleName" id="moduleName" value="${moduleName}"/>
					<input type="file" name="fileInput" id="fileInput" />
					<div id="fileQueue"></div>
					<input type="hidden" name="count" id="count"/>
				</dd>
			</dl>
		</div>
		<div class="formBar">
			<ul>
				<li><div class="buttonActive">
						<div class="buttonContent">
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							<a href="javascript:$('#fileInput').uploadifyClearQueue();">取消上传队列</a>
						</div>
					</div>
				</li>
			</ul>
			<ul>
				<li><div class="buttonActive">
						<div class="buttonContent">
						&nbsp;&nbsp;&nbsp;&nbsp;
							<a href="javascript:$('#fileInput').uploadifySettings('scriptData',{'auxiliaryId':document.getElementById('auxiliaryId').value,'uuid':document.getElementById('uuid').value,'moduleName':document.getElementById('moduleName').value,'count': document.getElementById('count').value,'typeid': document.getElementById('typeid').value,'typename': document.getElementById('typename').value}); javascript:$('#fileInput').uploadifyUpload();">开始上传</a>
						</div>
					</div>
				</li>
			</ul>
		</div>
	</div>
